//////////////////////////////////////////////////////////////////////////////////
//
//	AvaMods Redirect
//		- Version 1.1
//		- 04.14.2008
//		- diamond-optic
//
//////////////////////////////////////////////////////////////////////////////////
//
// Information:
//
//	- Menu for the AvaMods overflow server that
//	  allows clients to easily connect to the
//	  main avamods dod server...
//
//	- Delayed on-join message
//	- Repeating task message
//
//////////////////////////////////////////////////////////////////////////////////
//
// Changelog:
//
//	- 08.09.2006 Version 1.0
//		Initial release
//
//	- 04.14.2008 Version 1.1
//		Updated public cvar format
//		Various minor code improvements
//		Added password cvar
//		Changes for use on overflow server
//		Removed join msg CVAR
//		Added a repeating msg (with delay cvar)
//
//////////////////////////////////////////////////////////////////////////////////

#include <amxmodx>

#define VERSION "1.1"
#define SVERSION "v1.1 - by diamond-optic (www.AvaMods.com)"

new p_address,p_password,p_delay,p_repeat

public plugin_init()
{
	register_plugin("avamods redirect",VERSION,"diamond-optic")
	register_cvar("avamods_redirect_stats",SVERSION,FCVAR_SERVER|FCVAR_SPONLY)
	
	p_address = register_cvar("avamods_redirect_ip","8.2.121.202:27015")
	p_password = register_cvar("avamods_redirect_password","")
	
	p_delay = register_cvar("avamods_redirect_msgdelay","45")
	p_repeat = register_cvar("avamods_redirect_repeat","600")
	
	register_clcmd("say /servers","funcServers",0,"Show other servers")
	register_clcmd("say_team /servers","funcServers",0,"show other servers")
	
	register_menucmd(register_menuid("avamods_server_menu"),1023,"ServerMenuChoice") 
}

public plugin_cfg()
{
	new repeat = get_pcvar_num(p_repeat)
	
	if(repeat)
		set_task(float(repeat),"repeat_msg",0,"",0,"b") 
}

public client_putinserver(id)
	if(!is_user_bot(id) && is_user_connected(id)) 
		set_task(get_pcvar_float(p_delay),"ShowMsg",id)

public repeat_msg()
{
	client_print(0,print_chat,"** To try and switch to the main AvaMods server, type /servers in the chat **")
}

public ShowMsg(id)
{
	if(!is_user_bot(id) && is_user_connected(id)) 
		{
		client_print(id,print_chat,"** Welcome to the AvaMods Backup/Overflow Server **")
		
		client_print(id,print_chat,"** To try and switch to the main AvaMods server, type /servers in the chat **")
		}
}

public funcServers(id)
	if(!is_user_bot(id) && is_user_connected(id))	
		show_menu(id,(1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9),"avamods server menu^n^n 1.  Connect to other server^n 2.  Stay here",-1,"avamods_server_menu") 

public ServerMenuChoice(id, key) 
{ 
   if(is_user_connected(id))
	{	
	switch(key)
		{
		case 0: 
			{
			new password[32]
			get_pcvar_string(p_password,password,31)
			
			if(strlen(password) > 0)
				client_cmd(id,"setinfo password %s",password)
			
			new address[24]
			get_pcvar_string(p_address,address,23)
			
			client_cmd(id,"connect %s",address)
			}
		case 1: return PLUGIN_HANDLED
		}
	}
	
   return PLUGIN_CONTINUE
}
